#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node
{
	int a,b,f;
}l[100010],r[100010];
/*int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
void f(node &x)
{
	int &a=x.a,&b=x.b;
	if(a==0)
		return b=1,void();
	int g=gcd(a,b);
	a/=g,b/=g;
}*/
bool check(int x,node y)
{
	x=x*y.b;
	if(y.f==0)
		return (x>=y.a);
	if(y.f==1)
		return (x>y.a);
}
bool check2(int x,node y)
{
	x=x*y.b;
	if(y.f==0)
		return (x<=y.a);
	if(y.f==1)
		return (x<y.a);
}
int T,n,m,L,V,ans1,ans2,cnt,flg,sum[100010],ll[100010],R[100010],d[100010],v[100010],a[100010],p[100010];
vector<int> G[100010];
signed main()
{
	freopen("detect.in","r",stdin),freopen("detect.out","w",stdout);
	cin>>T;
	//T=10;
	while(T--)
	{
		cin>>n>>m>>L>>V,ans1=ans2=cnt=0,flg=1;
		for(int i=1;i<=n;i++)
		{
			cin>>d[i]>>v[i]>>a[i],cnt+=a[i];
			if(a[i]<0)
				flg=0;
			if(a[i]>0)
				l[i].a=2*a[i]*d[i]+V*V-v[i]*v[i],l[i].b=2*a[i],l[i].f=1,r[i].a=L,r[i].b=1;
			if(a[i]==0)
			{
				if(v[i]>V)
					l[i].a=d[i],l[i].b=1,r[i].a=L,r[i].b=1;
				else
					l[i].a=0,l[i].b=1,r[i].b=1,r[i].a=-1;
			}
			if(a[i]<0)
				l[i].a=d[i],l[i].b=1,r[i].a=2*a[i]*d[i]+V*V-v[i]*v[i],r[i].b=2*a[i],r[i].f=1;
			if(l[i].b<0)
				l[i].b=-l[i].b,l[i].a=-l[i].a;
			if(r[i].b<0)
				r[i].b=-r[i].b,r[i].a=-r[i].a;
			l[i].a=max(d[i]*l[i].b,l[i].a);
			//cout<<"111:"<<i<<' '<<l[i].a<<' '<<l[i].b<<' '<<r[i].a<<' '<<r[i].b<<'\n';
		}
		//cout<<"!";
		for(int i=1;i<=m;i++)
			cin>>p[i];
		for(int i=1;i<=n;i++)
		{
			//cout<<i<<"!!\n";
			int lll=1,rrr=m,ans=m+1;
			while(lll<=rrr)
			{
				int mid=(lll+rrr)/2;
				if(check(p[mid],l[i]))
					ans=mid,rrr=mid-1;
				else
					lll=mid+1;
			}
			ll[i]=ans,lll=1,rrr=m,ans=-1;
			while(lll<=rrr)
			{
				int mid=(lll+rrr)/2;
				if(check2(p[mid],r[i]))
					ans=mid,lll=mid+1;
				else
					rrr=mid-1;
			}
			R[i]=ans;
			if(ll[i]<=R[i])
				ans1++;
			//cout<<"222/"<<i<<": "<<ll[i]<<' '<<R[i]<<'\n';
		}
		if(cnt>=0&&flg==1)
			cout<<ans1<<' '<<(ans1==0?m:m-1)<<'\n';
		else
		{
			//cout<<"~\n";
			for(int i=1;i<=n;i++)
				for(int j=ll[i];j<=R[i];j++)
					G[j].push_back(i),sum[j]++;
			while(1)
			{
				//cout<<"333:"<<ans2<<'\n';
				int maxn=0,id=0;
				for(int i=1;i<=m;i++)
					if(sum[i]>maxn)
						maxn=sum[i],id=i;
				if(!maxn)
					break;
				ans2++;
				for(int i=1;i<=m;i++)
				{
					if(i==id)
						continue;
					for(int j=0;j<G[id].size();j++)
						for(int k=0;k<G[i].size();k++)
							if(G[i][k]==G[id][j]&&G[i][k]!=0)
								G[i][k]=0,sum[i]--;
				}
				G[id].clear(),sum[id]=0;
			}
			//cout<<"~~\n";
			cout<<ans1<<' '<<(m-ans2)<<'\n';
		}
	}
}
